home *** CD-ROM | disk | FTP | other *** search
/ Hot Metal Pro 4.0 / Hot Metal Pro 4.0.iso / HMPRO4 / cgi.z / wwwadmin.pl < prev    next >
Encoding:
Perl Script  |  1996-04-17  |  25.5 KB  |  659 lines

  1. #!/usr/local/bin/perl
  2.  
  3. ###########################################################################
  4. # WWWBoard Admin Tool
  5. # Version 2.0 ALPHA 2
  6. # Created by Matt Wright
  7. # Created on:  10/21/95         Last Modified on:  11/25/95
  8. # I can be reached at:          mattw@misha.net
  9. # Scripts Found at:             http://www.worldwidemart.com/scripts/
  10. ###########################################################################
  11.  
  12. ###########################################################################
  13. # Define Variables
  14.  
  15. $basedir = "/path/to/wwwboard";
  16. $baseurl = "http://your.host.xxx/wwwboard";
  17. $cgi_url = "http://your.host.xxx/cgi-bin/wwwadmin.pl";
  18.  
  19. $mesgdir = "messages";
  20. $datafile = "data.txt";
  21. $mesgfile = "wwwboard.html";
  22. $passwd_file = "passwd.txt";
  23.  
  24. $ext = "html";
  25.  
  26. $title = "WWWBoard Version 2.0 Test";
  27. $use_time = 1;        # 1 = YES; 0 = NO
  28.  
  29. # Done
  30. ###########################################################################
  31.  
  32. if ($ENV{'QUERY_STRING'} ne '') {
  33.    $command = "$ENV{'QUERY_STRING'}";
  34. }
  35. else {
  36.    &parse_form;
  37. }
  38.  
  39. print "Content-type: text/html\n\n";
  40.  
  41. ###########################################################################
  42. # Remove                                                                  #
  43. #       This option is useful to see how the threads appear in the        #
  44. #   wwwboard.html document.  It can give you a better idea of whether or  #
  45. #   not you want to remove the whole thread or just part of it.           #
  46. ###########################################################################
  47.  
  48. if ($command eq 'remove') {
  49.    print "<html><head><title>Remove Messages From WWWBoard</title></head>\n";
  50.    print "<body><center><h1>Remove Messages From WWWBoard</h1></center>\n";
  51.    print "Select below to remove those postings you wish to remove.\n";
  52.    print "Checking the Input Box on the left will remove the whole thread\n";
  53.    print "while checking the Input Box on the right to remove just that posting.<p>\n";
  54.    print "These messages have been left unsorted, so that you can see the order in\n";
  55.    print "which they appear in the $mesgpage page.  This will give you an idea oF\n";
  56.    print "what the threads look like and is often more helpful than the sorted method.\n";
  57.    print "<p>\n";
  58.    print "<hr size=7 width=75%><center><font size=-1>\n";
  59.    print "[ <a href=\"$cgi_url\?remove\">Remove</a> ] [ <a href=\"$cgi_url\?remove_by_date\">Remove by Date</a> ] [ <a href=\"$cgi_url\?remove_by_author\">Remove by Author</a> ] [ <a href=\"$cgi_url\?remove_by_num\">Remove by Message Number</a> ] [ <a href=\"$baseurl/$mesgpage\">$title</a> ]\n";
  60.    print "</font></center><hr size=7 width=75%><p>\n";
  61.    print "<form method=POST action=\"$cgi_url\">\n";
  62.    print "<input type=hidden name=\"action\" value=\"remove\">\n";
  63.    print "<table border>\n";
  64.    print "<tr>\n";
  65.    print "<th colspan=6>Username: <input type=text name=\"username\"> -- Password: <input type=password name=\"password\"></th>\n";
  66.    print "</tr><tr>\n";
  67.    print "<th>Post # </th><th>Thread </th><th>Single </th><th>Subject </th><th> Author</th><th> Date</th></tr>\n";
  68.  
  69.    open(MSGS,"$basedir/$mesgfile");
  70.    @lines = <MSGS>;
  71.    close(MSGS);
  72.  
  73.    foreach $line (@lines) {
  74.       if ($line =~ /<!--top: (.*)--><li><a href="$mesgdir\/\1\.$ext">(.*)<\/a> - <b>(.*)<\/b>\s+<i>(.*)<\/i>/) {
  75.          push(@ENTRIES,$1);
  76.          $SUBJECT{$1} = $2;
  77.          $AUTHOR{$1} = $3;
  78.          $DATE{$1} = $4;
  79.       }
  80.    }
  81.  
  82.    @SORTED_ENTRIES = (sort { $a <=> $b } @ENTRIES);
  83.    $max = pop(@SORTED_ENTRIES);
  84.    $min = shift(@SORTED_ENTRIES);
  85.  
  86.    print "<input type=hidden name=\"min\" value=\"$min\">\n";
  87.    print "<input type=hidden name=\"max\" value=\"$max\">\n";
  88.    print "<input type=hidden name=\"type\" value=\"remove\">\n";
  89.  
  90.    foreach (@ENTRIES) {
  91.       print "<tr>\n";
  92.       print "<th><b>$_</b> </th><td><input type=radio name=\"$_\" value=\"all\"> </td><td><input type=radio name=\"$_\" value=\"single\"> </td><td><a href=\"$baseurl/$mesgdir/$_\.$ext\">$SUBJECT{$_} </a></td><td>$AUTHOR{$_} </td><td>$DATE{$_}<br></td>\n";
  93.       print "</tr>\n";
  94.    }
  95.    print "</table>\n";
  96.    print "<center><p>\n";
  97.    print "<input type=submit value=\"Remove Messages\"> <input type=reset>\n";
  98.    print "</form>\n";
  99.    print "</body></html>\n";
  100. }
  101.  
  102. ###########################################################################
  103. # Remove By Number                                                        #
  104. #       This method is useful to see in what order the messages were      #
  105. #   added to the wwwboard.html document.                                  #
  106. ###########################################################################
  107.  
  108. elsif ($command eq 'remove_by_num') {
  109.    print "<html><head><title>Remove Messages From WWWBoard By Number</title></head>\n";
  110.    print "<body><center><h1>Remove Messages From WWWBoard By Number</h1></center>\n";
  111.    print "Select below to remove those postings you wish to remove.\n";
  112.    print "Checking the Input Box on the left will remove the whole thread\n";
  113.    print "while checking the Input Box on the right to remove just that posting.\n";
  114.    print "<p>\n";
  115.    print "<hr size=7 width=75%><center><font size=-1>\n";
  116.    print "[ <a href=\"$cgi_url\?remove\">Remove</a> ] [ <a href=\"$cgi_url\?remove_by_date\">Remove by Date</a> ] [ <a href=\"$cgi_url\?remove_by_author\">Remove by Author</a> ] [ <a href=\"$cgi_url\?remove_by_num\">Remove by Message Number</a> ] [ <a href=\"$baseurl/$mesgpage\">$title</a> ]\n";
  117.    print "</font></center><hr size=7 width=75%><p>\n";
  118.    print "<form method=POST action=\"$cgi_url\">\n";
  119.    print "<input type=hidden name=\"action\" value=\"remove\">\n";
  120.    print "<table border>\n";
  121.    print "<tr>\n";
  122.    print "<th colspan=6>Username: <input type=text name=\"username\"> -- Password: <input type=password name=\"password\"><br></th>\n";
  123.    print "</tr>\n";
  124.    print "<tr>\n";
  125.    print "<th>Post # </th><th>Thread </th><th>Single </th><th>Subject </th><th> Author</th><th> Date</th></tr>\n";
  126.  
  127.    open(MSGS,"$basedir/$mesgfile");
  128.    @lines = <MSGS>;
  129.    close(MSGS);
  130.  
  131.    foreach $line (@lines) {
  132.       if ($line =~ /<!--top: (.*)--><li><a href="$mesgdir\/\1\.$ext">(.*)<\/a> - <b>(.*)<\/b>\s+<i>(.*)<\/i>/) {
  133.          push(@ENTRIES,$1);
  134.          $SUBJECT{$1} = $2;
  135.          $AUTHOR{$1} = $3;
  136.          $DATE{$1} = $4;
  137.       }
  138.    }
  139.  
  140.    @SORTED_ENTRIES = (sort { $a <=> $b } @ENTRIES);
  141.    $max = pop(@SORTED_ENTRIES);
  142.    $min = shift(@SORTED_ENTRIES);
  143.    push(@SORTED_ENTRIES,$max);
  144.    unshift(@SORTED_ENTRIES,$min);
  145.  
  146.    print "<input type=hidden name=\"min\" value=\"$min\">\n";
  147.    print "<input type=hidden name=\"max\" value=\"$max\">\n";
  148.    print "<input type=hidden name=\"type\" value=\"remove\">\n";
  149.  
  150.    foreach (@SORTED_ENTRIES) {
  151.       print "<tr>\n";
  152.       print "<th><b>$_</b> </th><td><input type=radio name=\"$_\" value=\"all\"> </td><td><input type=radio name=\"$_\" value=\"single\"> </td><td><a href=\"$baseurl/$mesgdir/$_\.$ext\">$SUBJECT{$_} </a></td><td>$AUTHOR{$_} </td><td>$DATE{$_}<br></td>\n";
  153.       print "</tr>\n";
  154.    }
  155.    print "</table>\n";
  156.    print "<center><p>\n";
  157.    print "<input type=submit value=\"Remove Messages\"> <input type=reset>\n";
  158.    print "</form>\n";
  159.    print "</body></html>\n";
  160. }
  161.  
  162. ###########################################################################
  163. # Remove By Date                                                          #
  164. #       Using this method allows you to delete all messages posted before #
  165. #   a certain date.                                                       #
  166. ###########################################################################
  167.  
  168. elsif ($command eq 'remove_by_date') {
  169.    print "<html><head><title>Remove Messages From WWWBoard By Date</title></head>\n";
  170.    print "<body><center><h1>Remove Messages From WWWBoard By Date</h1></center>\n";
  171.    print "Select below to remove those postings you wish to remove.\n";
  172.    print "Checking the input box beside a date will remove all postings \n";
  173.    print "that occurred on that date.\n";
  174.    print "<p>\n";
  175.    print "<hr size=7 width=75%><center><font size=-1>\n";
  176.    print "[ <a href=\"$cgi_url\?remove\">Remove</a> ] [ <a href=\"$cgi_url\?remove_by_date\">Remove by Date</a> ] [ <a href=\"$cgi_url\?remove_by_author\">Remove by Author</a> ] [ <a href=\"$cgi_url\?remove_by_num\">Remove by Message Number</a> ] [ <a href=\"$baseurl/$mesgpage\">$title</a> ]\n";
  177.    print "</font></center><hr size=7 width=75%>\n";
  178.    print "<p>\n";
  179.    print "<form method=POST action=\"$cgi_url\">\n";
  180.    print "<input type=hidden name=\"action\" value=\"remove_by_date_or_author\">\n";
  181.    print "<input type=hidden name=\"type\" value=\"remove_by_date\">\n";
  182.    print "<center>\n";
  183.    print "<table border>\n";
  184.    print "<tr>\n";
  185.    print "<th colspan=4>Username: <input type=text name=\"username\"> -- Password: <input type=password name=\"password\"><br></th>\n";
  186.    print "</tr>\n";
  187.    print "<tr>\n";
  188.    print "<th>X </th><th>Date </th><th># of Messages </th><th>Message Numbers<br></th></tr>\n";
  189.  
  190.    open(MSGS,"$basedir/$mesgfile");
  191.    @lines = <MSGS>;
  192.    close(MSGS);
  193.  
  194.    foreach $line (@lines) {
  195.       if ($line =~ /<!--top: (.*)--><li><a href="$mesgdir\/\1\.$ext">.*<\/a> - <b>.*<\/b>\s+<i>(.*)<\/i>/) {
  196.          $date = $2;
  197.          if ($use_time == 1) {
  198.             ($time,$day) = split(/\s+/,$date);
  199.          }
  200.          else {
  201.             $day = $date;
  202.          }
  203.          $DATE{$1} = $day;
  204.       }
  205.    }
  206.  
  207.    undef(@used_values);
  208.    foreach $value (sort (values %DATE)) {
  209.       $match = '0';
  210.       $value_number = 0;
  211.       foreach $used_value (@used_values) {
  212.          if ($value eq $used_value) {
  213.             $match = '1';
  214.             last;
  215.          }
  216.       }
  217.       if ($match == '0') {
  218.          undef(@values); undef(@short_values);
  219.          foreach $key (keys %DATE) {
  220.             if ($value eq $DATE{$key}) {
  221.                $key_url = "<a href=\"$baseurl/$mesgdir/$key\.$ext\">$key</a>";
  222.                push(@values,$key_url);
  223.            push(@short_values,$key);
  224.                $value_number++;
  225.             }
  226.          }
  227.          $form_value = $value;
  228.          $form_value =~ s/\//_/g;
  229.          print "<tr>\n";
  230.          print "<td><input type=checkbox name=\"$form_value\" value=\"@short_values\"> </td><th>$value </th><td>$value_number </td><td>@values<br></td>\n";
  231.          print "</tr>\n";
  232.          push(@used_values,$value);
  233.          push(@used_form_values,$form_value);
  234.       }
  235.    }
  236.    print "</table><p>\n";
  237.    print "<input type=hidden name=\"used_values\" value=\"@used_form_values\">\n";
  238.    print "<input type=submit value=\"Remove Messages\"> <input type=reset>\n";
  239.    print "</form></center>\n";
  240.    print "</body></html>\n";
  241. }
  242.  
  243. ###########################################################################
  244. # Remove By Author                                                        #
  245. #       This option makes a list of all known authors and then groups     #
  246. #    together there postings and allows you to remove them all at once.   #
  247. ###########################################################################
  248.  
  249. elsif ($command eq 'remove_by_author') {
  250.    print "<html><head><title>Remove Messages From WWWBoard By Author</title></head>\n";
  251.    print "<body><center><h1>Remove Messages From WWWBoard By Author</h1></center>\n";
  252.    print "Checking the checkbox beside the name of an author will remove \n";
  253.    print "all postings which that author has created.\n";
  254.    print "<p>\n";
  255.    print "<hr size=7 width=75%><center><font size=-1>\n";
  256.    print "[ <a href=\"$cgi_url\?remove\">Remove</a> ] [ <a href=\"$cgi_url\?remove_by_date\">Remove by Date</a> ] [ <a href=\"$cgi_url\?remove_by_author\">Remove by Author</a> ] [ <a href=\"$cgi_url\?remove_by_num\">Remove by Message Number</a> ] [ <a href=\"$baseurl/$mesgpage\">$title</a> ]\n";
  257.    print "</font></center><hr size=7 width=75%>\n";
  258.    print "<p>\n";
  259.    print "<form method=POST action=\"$cgi_url\">\n";
  260.    print "<input type=hidden name=\"action\" value=\"remove_by_date_or_author\">\n";
  261.    print "<input type=hidden name=\"type\" value=\"remove_by_author\">\n";
  262.    print "<center>\n";
  263.    print "<table border>\n";
  264.    print "<tr>\n";
  265.    print "<th colspan=4>Username: <input type=text name=\"username\"> -- Password: <input type=password name=\"password\"><br></th>\n";
  266.    print "</tr>\n";
  267.    print "<tr>\n";
  268.    print "<th>X </th><th>Author </th><th># of Messages </th><th>Message #'s<br></th></tr>\n";
  269.  
  270.    open(MSGS,"$basedir/$mesgfile");
  271.    @lines = <MSGS>;
  272.    close(MSGS);
  273.  
  274.    foreach $line (@lines) {
  275.       if ($line =~ /<!--top: (.*)--><li><a href="$mesgdir\/\1\.$ext">.*<\/a> - <b>(.*)<\/b>\s+<i>.*<\/i>/) {
  276.          $AUTHOR{$1} = $2;
  277.       }
  278.    }
  279.  
  280.    undef(@used_values);
  281.    foreach $value (sort (values %AUTHOR)) {
  282.       $match = '0';
  283.       $value_number = 0;
  284.       foreach $used_value (@used_values) {
  285.          if ($value eq $used_value) {
  286.             $match = '1';
  287.             last;
  288.          }
  289.       }
  290.       if ($match == '0') {
  291.          undef(@values); undef(@short_values);
  292.          foreach $key (keys %AUTHOR) {
  293.             if ($value eq $AUTHOR{$key}) {
  294.                $key_url = "<a href=\"$baseurl/$mesgdir/$key\.$ext\">$key</a>";
  295.                push(@values,$key_url);
  296.                push(@short_values,$key);
  297.                $value_number++;
  298.             }
  299.          }
  300.          $form_value = $value;
  301.          $form_value =~ s/ /_/g;
  302.          print "<tr>\n";
  303.          print "<td><input type=checkbox name=\"$form_value\" value=\"@short_values\"> </td><th align=left>$value </th><td>$value_number </td><td>@values<br></td>\n";
  304.          print "</tr>\n";
  305.          push(@used_values,$value);
  306.          push(@used_form_values,$form_value);
  307.       }
  308.    }
  309.    print "</table><p>\n";
  310.    print "<input type=hidden name=\"used_values\" value=\"@used_form_values\">\n";
  311.    print "<input type=submit value=\"Remove Messages\"> <input type=reset>\n";
  312.    print "</form></center>\n";
  313.    print "</body></html>\n";
  314.  
  315. }
  316.  
  317. ###########################################################################
  318. # Change Password                                                         #
  319. #       By calling this section of the script, the admin can change his or#
  320. #   her password.                              #
  321. ###########################################################################
  322.  
  323. elsif ($command eq 'change_passwd') {
  324.  
  325.    print "<html><head><title>Change WWWBoard Admin Password</title></head>\n";
  326.    print "<body><center><h1>Change WWWBoard Admin Password</h1></center>\n";
  327.    print "Fill out the form below completely to change your password and user name.\n";
  328.    print "If new username is left blank, your old one will be assumed.<p><hr size=7 width=75%><p>\n";
  329.    print "<form method=POST action=\"$cgi_url\">\n";
  330.    print "<input type=hidden name=\"action\" value=\"change_passwd\">\n";
  331.    print "<center><table border=0>\n";
  332.    print "<tr>\n";
  333.    print "<th align=left>Username: </th><td><input type=text name=\"username\"><br></td>\n";
  334.    print "</tr><tr>\n";
  335.    print "<th align=left>Password: </th><td><input type=password name=\"password\"><br></td>\n";
  336.    print "</tr><tr> </tr><tr>\n";
  337.    print "<th align=left>New Username: </th><td><input type=text name=\"new_username\"><br></td>\n";
  338.    print "</tr><tr>\n";
  339.    print "<th align=left>New Password: </th><td><input type=password name=\"passwd_1\"><br></td>\n";
  340.    print "</tr><tr>\n";
  341.    print "<th align=left>Re-type New Password: </th><td><input type=password name=\"passwd_2\"><br></td>\n";
  342.    print "</tr><tr>\n";
  343.    print "<td align=center><input type=submit value=\"Change Password\"> </td><td align=center><input type=reset></td>\n";
  344.    print "</tr></table></center>\n";
  345.    print "</form></body></html>\n";
  346.  
  347. }
  348.  
  349. ###########################################################################
  350. # Remove Action                                                           #
  351. #       This portion is used by the options remove and remove_by_num.     #
  352. ###########################################################################
  353.  
  354. elsif ($FORM{'action'} eq 'remove') {
  355.  
  356.    &check_passwd;
  357.  
  358.    for ($i = $FORM{'min'}; $i <= $FORM{'max'}; $i++) {
  359.       if ($FORM{$i} eq 'all') {
  360.          push(@ALL,$i);
  361.       }
  362.       elsif ($FORM{$i} eq 'single') {
  363.          push(@SINGLE,$i);
  364.       }
  365.    }
  366.  
  367.    open(MSGS,"$basedir/$mesgfile");
  368.    @lines = <MSGS>;
  369.    close(MSGS);
  370.  
  371.    foreach $single (@SINGLE) {
  372.       foreach ($j = 0;$j <= @lines;$j++) {
  373.          if ($lines[$j] =~ /<!--top: $single-->/) {
  374.             splice(@lines, $j, 3);
  375.             $j -= 3;
  376.          }
  377.          elsif ($lines[$j] =~ /<!--end: $single-->/) {
  378.             splice(@lines, $j, 1);
  379.             $j--;
  380.          }
  381.       }
  382.       $filename = "$basedir/$mesgdir/$single\.$ext";
  383.       if (-e $filename) {
  384.          unlink("$filename") || push(@NOT_REMOVED,$single);
  385.       }
  386.       else {
  387.          push(@NO_FILE,$single);
  388.       }
  389.       push(@ATTEMPTED,$single);
  390.    }
  391.  
  392.    foreach $all (@ALL) {
  393.       undef($top); undef($bottom);
  394.       foreach ($j = 0;$j <= @lines;$j++) {
  395.          if ($lines[$j] =~ /<!--top: $all-->/) {
  396.             $top = $j;
  397.          }
  398.          elsif ($lines[$j] =~ /<!--end: $all-->/) {
  399.             $bottom = $j;
  400.          }
  401.       }
  402.       if ($top && $bottom) {
  403.          $diff = ($bottom - $top);
  404.          $diff++;
  405.          for ($k = $top;$k <= $bottom;$k++) {
  406.             if ($lines[$k] =~ /<!--top: (.*)-->/) {
  407.                push(@DELETE,$1);
  408.             }
  409.          }
  410.          splice(@lines, $top, $diff);
  411.          foreach $delete (@DELETE) {
  412.             $filename = "$basedir/$mesgdir/$delete\.$ext";
  413.             if (-e $filename) {
  414.                unlink($filename) || push(@NOT_REMOVED,$delete);
  415.             }
  416.             else {
  417.                push(@NO_FILE,$delete);
  418.             }
  419.             push(@ATTEMPTED,$delete);
  420.          }
  421.       }
  422.       else {
  423.          push(@TOP_BOT,$all);
  424.       }
  425.    }
  426.  
  427.    open(WWWBOARD,">$basedir/$mesgfile");
  428.    print WWWBOARD @lines;
  429.    close(WWWBOARD);      
  430.  
  431.    &return_html($FORM{'type'});
  432.  
  433. }
  434.  
  435. ###########################################################################
  436. # Remove Action by Date or Author                                         #
  437. #       This portion is used by the method remove_by_date or           #
  438. #   remove_by_author.                                 #
  439. ###########################################################################
  440.  
  441. elsif ($FORM{'action'} eq 'remove_by_date_or_author') {
  442.  
  443.    &check_passwd;
  444.  
  445.    @used_values = split(/\s/,$FORM{'used_values'});
  446.    foreach $used_value (@used_values) {
  447.       @misc_values = split(/\s/,$FORM{$used_value});
  448.       foreach $misc_value (@misc_values) {
  449.          push(@SINGLE,$misc_value);
  450.       }
  451.    }
  452.  
  453.    open(MSGS,"$basedir/$mesgfile");
  454.    @lines = <MSGS>;
  455.    close(MSGS);
  456.  
  457.    foreach $single (@SINGLE) {
  458.       foreach ($j = 0;$j <= @lines;$j++) {
  459.          if ($lines[$j] =~ /<!--top: $single-->/) {
  460.             splice(@lines, $j, 3);
  461.             $j -= 3;
  462.          }
  463.          elsif ($lines[$j] =~ /<!--end: $single-->/) {
  464.             splice(@lines, $j, 1);
  465.             $j--;
  466.          }
  467.       }
  468.       $filename = "$basedir/$mesgdir/$single\.$ext";
  469.       if (-e $filename) {
  470.          unlink("$filename") || push(@NOT_REMOVED,$single);
  471.       }
  472.       else {
  473.          push(@NO_FILE,$single);
  474.       }
  475.       push(@ATTEMPTED,$single);
  476.    }
  477.  
  478.    open(WWWBOARD,">$basedir/$mesgfile");
  479.    print WWWBOARD @lines;
  480.    close(WWWBOARD);
  481.  
  482.    &return_html($FORM{'type'});
  483.  
  484. }
  485.  
  486. elsif ($FORM{'action'} eq 'change_passwd') {
  487.  
  488.    open(PASSWD,"$basedir/$passwd_file") || &error(passwd_file);
  489.    $passwd_line = <PASSWD>;
  490.    chop($passwd_line) if $passwd_line =~ /\n$/;
  491.    close(PASSWD);
  492.  
  493.    ($username,$passwd) = split(/:/,$passwd_line);
  494.  
  495.    if (!($FORM{'passwd_1'} eq $FORM{'passwd_2'})) {
  496.       &error(not_same);
  497.    }
  498.  
  499.    $test_passwd = crypt($FORM{'password'}, substr($passwd, 0, 2));
  500.    if ($test_passwd eq $passwd && $FORM{'username'} eq $username) {
  501.       open(PASSWD,">$basedir/$passwd_file") || &error(no_change);
  502.       $new_password = crypt($FORM{'passwd_1'}, substr($passwd, 0, 2));
  503.       if ($FORM{'new_username'}) {
  504.          $new_username = $FORM{'new_username'};
  505.       }
  506.       else {
  507.          $new_username = $username;
  508.       }
  509.       print PASSWD "$new_username:$new_password";
  510.       close(PASSWD);
  511.    }
  512.    else {
  513.       &error(bad_combo);
  514.    }
  515.  
  516.    &return_html(change_passwd);
  517. }
  518.  
  519. else {
  520.    print "<html><head><title>WWWAdmin For WWWBoard</title></head>\n";
  521.    print "<body bgcolor=#FFFFFF text=#000000><center><h1>WWWAdmin For WWWBoard</h1></center>\n";
  522.    print "Choose your Method of modifying WWWBoard Below:<p>\n";
  523.    print "<hr size=7 width=75%><br>\n";
  524.    print "<ul>\n";
  525.    print "<li>Remove Files\n";
  526.    print "<ul>\n";
  527.    print "<li><a href=\"$cgi_url\?remove\">Remove Files</a>\n";
  528.    print "<li><a href=\"$cgi_url\?removeby_num\">Remove Files by Mesage Number</a>\n";
  529.    print "<li><a href=\"$cgi_url\?remove_by_date\">Remove Files by Date</a>\n";
  530.    print "<li><a href=\"$cgi_url\?remove_by_author\">Remove Files by Author</a>\n";
  531.    print "</ul><br>\n";
  532.    print "<li>Password\n";
  533.    print "<ul>\n";
  534.    print "<li><a href=\"$cgi_url\?change_passwd\">Change Admin Password</a>\n";
  535.    print "</ul>\n";
  536.    print "</ul>\n";
  537. }
  538.  
  539. #######################
  540. # Parse Form Subroutine
  541.  
  542. sub parse_form {
  543.  
  544.    # Get the input
  545.    read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
  546.  
  547.    # Split the name-value pairs
  548.    @pairs = split(/&/, $buffer);
  549.  
  550.    foreach $pair (@pairs) {
  551.       ($name, $value) = split(/=/, $pair);
  552.  
  553.       # Un-Webify plus signs and %-encoding
  554.       $value =~ tr/+/ /;
  555.       $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
  556.  
  557.       $FORM{$name} = $value;
  558.    }
  559. }
  560.  
  561. sub return_html {
  562.    $type = $_[0];
  563.    if ($type eq 'remove') {
  564.       print "<html><head><title>Results of Message Board Removal</title></head>\n";
  565.       print "<body><center><h1>Results of Message Board Removal</h1></center>\n";
  566.    }
  567.    elsif ($type eq 'remove_by_num') {
  568.       print "<html><head><title>Results of Message Board Removal by Number</title></head>\n";
  569.       print "<body><center><h1>Results of Message Board Removal by Number</h1></center>\n";
  570.    }
  571.    elsif ($type eq 'remove_by_date') {
  572.       print "<html><head><title>Results of Message Board Removal by Date</title></head>\n";
  573.       print "<body><center><h1>Results of Message Board Removal by Date</h1></center>\n";
  574.    }
  575.    elsif ($type eq 'remove_by_author') {
  576.       print "<html><head><title>Results of Message Board Removal by Author</title></head>\n";
  577.       print "<body><center><h1>Results of Message Board Removal by Author</h1></center>\n";
  578.    }
  579.    elsif ($type eq 'change_passwd') {
  580.       print "<html><head><title>WWWBoard WWWAdmin Password Changed</title></head>\n";
  581.       print "<body><center><h1>WWWBoard WWWAdmin Password Changed</h1></center>\n";
  582.       print "Your Password for WWWBoard WWWAdmin has been changed!  Results are below:<p><hr size=7 width=75%><p>\n";
  583.       print "<b>New Username: $new_username<p>\n";
  584.       print "New Password: $FORM{'passwd_1'}</b><p>\n";
  585.       print "<hr size=7 width=75%><p>\n";
  586.       print "Do not forget these, since they are now encoded in a file, and not readable!.\n";
  587.       print "</body></html>\n";
  588.    }
  589.    if ($type =~ /^remove/) {
  590.       print "Below is a short summary of what messages were removed from $mesgpage and the\n";
  591.       print "$mesgdir directory.  All files that the script attempted to remove, were removed,\n";
  592.       print "unless there is an error message stating otherwise.<p><hr size=7 width=75%><p>\n";
  593.  
  594.       print "<b>Attempted to Remove:</b> @ATTEMPTED<p>\n";
  595.       if (@NOT_REMOVED) {
  596.          print "<b>Files That Could Not Be Deleted:</b> @NOT_REMOVED<p>\n";
  597.       }
  598.       if (@NO_FILE) {
  599.          print "<b>Files Not Found:</b> @NO_FILE<p>\n";
  600.       }
  601.       print "<hr size=7 width=75%><center><font size=-1>\n";
  602.       print "[ <a href=\"$cgi_url\?remove\">Remove</a> ] [ <a href=\"$cgi_url\?remove_by_date\">Remove by Date</a> ] [ <a href=\"$cgi_url\?remove_by_author\">Remove by Author</a> ] [ <a href=\"$cgi_url\?remove_by_num\">Remove by Message Number</a> ] [ <a href=\"$baseurl/$mesgpage\">$title</a> ]\n";
  603.       print "</font></center><hr size=7 width=75%>\n";
  604.       print "</body></html>\n";
  605.    }
  606. }
  607.  
  608. sub error {
  609.    $error = $_[0];
  610.    if ($error eq 'bad_combo') {
  611.       print "<html><head><title>Bad Username - Password Combination</title></head>\n";
  612.       print "<body><center><h1>Bad Username - Password Combination</h1></center>\n";
  613.       print "You entered and invalid username password pair.  Please try again.<p>\n";
  614.       &passwd_trailer
  615.    }
  616.    elsif ($error eq 'passwd_file') {
  617.       print "<html><head><title>Could Not Open Password File For Reading</title></head>\n";
  618.       print "<body><center><h1>Could Not Open Password File For Reading</h1></center>\n";
  619.       print "Could not open the password file for reading!  Check permissions and try again.<p>\n";
  620.       &passwd_trailer
  621.    }
  622.    elsif ($error eq 'not_same') {
  623.       print "<html><head><title>Incorrect Password Type-In</title></head>\n";
  624.       print "<body><center><h1>Incorrect Password Type-In</h1></center>\n";
  625.       print "The passwords you typed in for your new password were not the same.\n";
  626.       print "You may have mistyped, please try again.<p>\n";
  627.       &passwd_trailer
  628.    }
  629.    elsif ($error eq 'no_change') {
  630.       print "<html><head><title>Could Not Open Password File For Writing</title></head>\n";
  631.       print "<body><center><h1>Could Not Open Password File For Writing</h1></center>\n";
  632.       print "Could not open the password file for writing!  Password not changed!<p>\n";
  633.       &passwd_trailer
  634.    }
  635.  
  636.    exit;
  637. }
  638.  
  639. sub passwd_trailer {
  640.    print "<hr size=7 width=75%><center><font size=-1>\n";
  641.    print "[ <a href=\"$cgi_url\">WWWAdmin</a> ] [ <a href=\"$baseurl/$mesgpage\">$title</a> ]\n";
  642.    print "</font></center><hr size=7 width=75%>\n";
  643.    print "</body></html>\n";
  644. }
  645.  
  646. sub check_passwd {
  647.    open(PASSWD,"$basedir/$passwd_file") || &error(passwd_file);
  648.    $passwd_line = <PASSWD>;
  649.    chop($passwd_line) if $passwd_line =~ /\n$/;
  650.    close(PASSWD);
  651.  
  652.    ($username,$passwd) = split(/:/,$passwd_line);
  653.  
  654.    $test_passwd = crypt($FORM{'password'}, substr($passwd, 0, 2));
  655.    if (!($test_passwd eq $passwd && $FORM{'username'} eq $username)) {
  656.       &error(bad_combo);
  657.    }
  658. }
  659.